#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 20005
int N, M;
int Size[maxn], Parent[maxn];
void init()
{
    fill(Size, Size + N + 1, 1);
    fill(Parent, Parent + N + 1, -1);
}
int findParent(int x)
{
    if (Parent[x] == -1 || Parent[x] == x)
        return x;
    int par;
    par = findParent(Parent[x]);
    Parent[x] = par;
    return par;
}
void Union(int x, int y)
{
    int xpar = findParent(x);
    int ypar = findParent(y);
    if (Size[xpar] < Size[ypar])
    {
        Parent[xpar] = ypar;
        Size[ypar] += Size[xpar];
    }
    else
    {
        Parent[ypar] = xpar;
        Size[xpar] += Size[ypar];
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin >> N >> M;
    init();
    for (int i = 1, z, x, y, parx, pary; i <= M; ++i)
    {
        cin >> z >> x >> y;
        if (z == 1)
        {
            Union(x, y);
        }
        else if (z == 2)
        {
            parx = findParent(x);
            pary = findParent(y);
            cout << (parx == pary ? "Y" : "N") << endl;
        }
    }
    return 0;
}